var windowName = "myShopOrderInfo";
var Page;
apiready = function () {
    onWindowShow(function () {
        console.log(windowName + " show")
    })
    onWindowHide(function () {
        console.log(windowName + " hide")
    })
    console.log("index page is OK");
    Page = createVM("#Page", {
            id: 0,
            curTab: 0,
            star: 5,
            content: "",
            en: {
                "id": 36,
                "user": {
                    "id": 1,
                    "name": "用户_15265461237",
                    "phone": "15265461237",
                    "avatar": "/ApiCloud/assets/img/userHead.jpeg"
                },
                "cat1": {
                    "id": 1,
                    "name": "行业一",
                    "pic": "/ApiCloud/assets/icons/1.png"
                },
                "cat2": {
                    "id": 10,
                    "name": "分二",
                    "pic": "/ApiCloud/assets/icons/2.png"
                },
                "favor": [],
                "favorProvince": "山东省",
                "favorCity": "东营市",
                "favorArea": "",
                "title": "和弟弟",
                "tips": "意图土豪",
                "address": {
                    "id": 4,
                    "province": "山东省",
                    "city": "东营市",
                    "area": "东营区",
                    "address": "东营市赛拉维广场-7栋",
                    "lat": 37.412543,
                    "lon": 118.661927,
                    "code": 370502
                },
                "contact": {
                    "id": 3,
                    "name": "洪三哥",
                    "phone": "15265461237"
                },
                "sn": "202001162240042528",
                "bookAt": "2020-01-16T14:30:19+08:00",
                "expireAt": "2020-02-15T22:40:04+08:00",
                "hireAt": null,
                "confirmAt": null,
                "finishAt": null,
                "createAt": "2020-01-16T22:40:04+08:00",
                "status": 0,
                "pics": ["http://sano100-tjb.oss-cn-beijing.aliyuncs.com/qz/2HS3QQdts5xpk3P3kCMFnHAGGPtnnkpMDJs2wmbf6Ynb26TamxCE3aNy3deDnpX3.jpg"],
                "type": null
            }
            ,votes:[]
            ,choosed:{
                "id":2,
                "user":{
                    "id":1,
                    "name":"用户_15265461237",
                    "phone":"15265461237",
                    "avatar":"/ApiCloud/assets/img/userHead.jpeg"
                },
                "task":"/api_/tasks/90",
                "price":99,
                "priceMax":null,
                "status":0,
                "tips":"无",
                "createAt":"2020-01-17T16:07:25+08:00"
            }
            ,cancelList:["不需要了","发错了","误操作","其他"]
            ,confirmList:["服务态度好","专业","认真负责","满星好评","赞，非常赞","棒棒哒"]
            ,showAppeal:false
            ,appealContent:""
        },
        {
            //页面方法
            "init": function () {
                var data = getData4Page()
                var id = data.id
                this.id = id;
                getData()
            }
            , tab: function (index) {
                log(index)
                Page.curTab = index
                startPullUpLoadMore();
            }
            , setStar: function (index) {
                this.star = index
            }
            ,hire:function (id) {
                apiPost("/api/task/hire/" + id,{},function (res , code) {
                    log(res)
                    if (code ==200 ) {
                        getVotes()
                        getData()
                    }
                    showToast(res.message);
                })
            }
            , cancel:function (id) {
                apiGet("/api/task/" + id + "/cancel",{},function (res , code) {
                    log(res)
                    if (code ==200 ) {
                        showToast(res.message);
                        gobackDelay()
                    }
                })
            }
            , confirm:function (id) {
                apiGet("/api/task/" + id + "/done",{score:this.start,content:this.content},function (res , code) {
                    log(res)
                    if (code ==200 ) {
                        showToast(res.message);
                        gobackDelay()
                    }
                })
            }
            , appeal: function (id) {
                if (!isTrue(this.appealContent)) {
                    showToast("请说明投诉原因");
                    return false;
                }
                apiPost("/api/task/" + id + "/appeals",{content:this.appealContent},function (res , code) {
                    log(res)
                    if (code ==200 ) {
                        showToast(res.message);
                    }
                });

            }
        })
    Page.init()
}

function getData() {
    Page.loading = true;
    apiGet("/app/task/" + Page.id, {}, function (res, code) {
        clearLoading();
        if (code == 200) {
            Page.en = res.data
        } else {
            showToast(code)
        }
    })
}


